package com.file.manage.controller;

import com.file.manage.domain.request.UpdatePasswordRequest;
import com.file.manage.infrastructure.base.CommonResult;
import com.file.manage.domain.request.RegisterRequest;
import com.file.manage.domain.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;;

/**
 * 认证相关接口
 *
 * @author Hollis
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("auth")
@Tag(name = "认证相关接口")
public class AuthController {
    @Resource
    private UserService userService;


    @Operation(summary  = "用户注册")
    @RequestMapping(value = "/register", method = RequestMethod.POST)
    public CommonResult<?> register(@Valid @RequestBody RegisterRequest registerRequest) {
        userService.register(registerRequest);
        return CommonResult.success();
    }

    @Operation(summary  = "用户登录")
    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public CommonResult<String> login(@RequestParam("account") String account, @RequestParam("password") String password) {
        return CommonResult.success(userService.login(account, password));
    }
    @Operation(summary = "修改密码")
    @RequestMapping(value = "/updatePassword", method = RequestMethod.POST)
    public CommonResult<?> updatePassword(@Valid @RequestBody UpdatePasswordRequest request) {
        userService.updatePassword(request);
        return CommonResult.success();
    }
}
